// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: log_factory.hpp 216 2008-09-03 08:13:29Z heavyzheng $
//

#ifndef ZZHENG_LOGGING_NONE_LOG_FACTORY_HPP_20080902__
#define ZZHENG_LOGGING_NONE_LOG_FACTORY_HPP_20080902__

#include <zzheng/logging/none/config.hpp>
#include <zzheng/logging/none/logger.hpp>
#include <zzheng/logging/log_level.hpp>
#include <zzheng/logging/destination.hpp>

#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#include <string>
#include <map>

namespace zzheng {
namespace logging {
namespace none_ {

    //! The log factory implementation which does nothing.
    class ZZHENG_LOGGING_DECL log_factory: private boost::noncopyable {

        typedef std::map<std::string, destination> destination_map;

    public:

        typedef logger logger_type; //!< The logger class typedef, required by wrapping templates.

    public:

        //! Returns the singleton log factory instance.
        //! \return the singleton log factory instance.
        static log_factory& instance();

        //! Sets the default threshold to the log factory. The default threshold will not take
        //! effect until configure() is called.
        //! \param threshold  the default threshold to set.
        void set_threshold(const log_level& threshold);

        //! Adds a logging destination to the log factory. The new logging destination will not
        //! take effect until configure() is called.
        //! \param name  the name of the logging destination.
        //! \param dest  the logging destination.
        void add_destination(const std::string& name, const destination& dest);

        //! Configures the log factory.
        //! \return true if the log factory is configured successfully, false otherwise.
        bool configure();

        //! Returns the reference to the root logger.
        //! \return the reference to the root logger.
        boost::weak_ptr<logger> get_root();

        //! Returns a named logger. If the logger exists in this factory, it is returned by copy.
        //! If it does not yet exists in this factory, it is firstly created, and registered into
        //! this factory, and then returned by copy.
        //! \param name  the name of the logger.
        //! \return the named logger.
        //boost::weak_ptr<logger> get_logger(const std::string& name);

    private:

        //! Private default constructor.
        explicit log_factory();

        //! Private destructor.
        ~log_factory();

    private:

        boost::shared_ptr<logger> root_;
        log_level                 threshold_;
        destination_map           dests_;

    }; // class log_factory

} // namespace zzheng::logging::none_
} // namespace zzheng::logging
} // namespace zzheng

#endif // ZZHENG_LOGGING_NONE_LOG_FACTORY_HPP_20080902__



